package trabalho.das.fxml.views.uicomponents;

import entidades.util.Grelha;
import entidades.util.LinhaDaGrelha;
import javafx.beans.binding.Bindings;
import javafx.beans.value.ObservableValue;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;

/**
 * Trabalho DAS - 2014/2015
 * @author a21210380, a21190325, a21210392
 */
public class MyLine extends Line {
    
    public MyLine(Grelha grelha, LinhaDaGrelha l) {
        this(grelha, l, l.getInicio().getX(), l.getInicio().getY(), l.getFim().getX(), l.getFim().getY());
    }
    
    public MyLine(Grelha grelha, LinhaDaGrelha l, float x, float y, float x1, float y1) {
        super(x, y, x1, y1);
        setStrokeWidth(0.1d);
        
        Bindings.bindBidirectional(visibleProperty(), grelha.visivelProperty());
        
        l.selecionadaProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
            if(newValue) {
                setStroke(Color.RED);
                setStrokeWidth(0.6d);
            } else {
                setStroke(Color.BLACK);
                setStrokeWidth(0.1d);
            }
        });
    }

}
